#include <stdio.h>

int main()
{
#if 0    
    int val1 = 100;
    int val2 = 200;

    char sex = 'm';

    int val3 = 300;

    printf("&val1 = %p\n", &val1);
    printf("&val2 = %p\n", &val2);
    printf("&sex = %p\n", &sex);
    printf("&val3 = %p\n", &val3);
#endif

#if 0
    /*数组的定义*/
    /*int num[x]        x:表示数组里有多少个元素*/
    int nums[8];
    int a[10] = { 0 };
    int flag[] = { 12, 312, 3, 4, 432, 51, 62, 62, 26, 232, 632, 22, 73, 83, 83, 3, 26, 3 };
    int eleNum = sizeof(flag) / sizeof(int);
    printf("eleNum = %d\n", eleNum);

    /*数组的赋值*/
    nums[0] = 70;
    nums[1] = 123;
    nums[2] = 90;
    nums[3] = 97;
    nums[7] = 78;

    /*数组的取值*/
    printf("nums[3] = %d\n", nums[3]);
    
    /*数组元素的地址*/
    for (int idx = 0; idx < 8; idx++)
    {
        printf("&nums[%d] = %p\n", idx, &nums[idx]);
    }

    /*数组的内存*/
    int length = sizeof(nums);
    printf("length = %d\n", length);

    /*脏数据 —— 未初始化随机的值*/
    int array[10];
    for (int idx = 0; idx < 10; idx++)
    {
        printf("array[%d] = %d\n", idx, array[idx]);
    }
#endif

#if 0
    /*相同的数据类型*/
    int nums[5];

    /*赋值*/
    nums[0] = 12;
    nums[1] = 99.90;
    nums[2] = 'm';
#endif

#if 0
    /*字符数组*/
    char array[6];

    /*赋值*/
    array[0] = 'h';
    array[1] = 'e';
    array[2] = 'l';
    array[3] = 'l';
    array[4] = 'o';

    /*取值*/
    for (int idx = 0; idx < 6; idx++)
    {
        printf("array[%d] = %c\n", idx, array[idx]);
    }

    /*内存*/
    int size = sizeof(array);
    printf("size = %d\n", size);

    /*地址*/
    for (int idx = 0; idx < 6; idx++)
    {
        printf("&array[%d] = %p\n", idx, &array[idx]);
    }
#endif

#if 0
    /* 二维数组 *//* 定义 */
    int a[3][4];//3行4列 —— 行：row  列：col

    /* 内存 */
    int size = sizeof(a);
    printf("size = %d\n", size);

    /* 赋值 */
    int num[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};

    /* 取值 */
    for (int idx = 0; idx < 3; idx++)
    {
        for (int jdx = 0; jdx < 4; jdx++)
        {
            printf("num[%d][%d] = %d\t", idx, jdx, num[idx][jdx]);
        }
        printf("\n");
    }
#endif

#if 0
    /* 地址 */
    int nums[5] = {12, 13, 21, 7};
    
    /* 数组0号元素的地址 */
    printf("&nums[0] = %p\n", &nums[0]);
    /* 数组名到底是什么？  ——  数组名就是数组首元素的地址 */
    printf("&nums[0] = %p\n", nums);

    /* 数组名是地址，地址是常量，常量不能被改变 */
    //nums = 0x7ffda9da9d10;
#endif

#if 0
    /* 二维数组 */
    int array[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};

    /* 二维数组：数组的数组名 = 数组第一行的地址 = 数组首元素的地址 */
    printf("&array[0][0] = %p\n", &array[0][0]);
    printf("array = %p\n", array);
    printf("array[0] = %p\n", array[0]);
    /* 二维数组的邻行相差内存地址取决于每一行的元素个数 */
    printf("array[1] = %p\n", array[1]);
    printf("array[2] = %p\n", array[2]);

    printf("&array[0][1] = %p\n", &array[0][1]);
    printf("array[0] + 1 = %p\n", array[0] + 1);//下一个元素的地址
#endif

#if 0
    /* 字符数组 */

#if 0    
    char buffer[15];
    /* 这种定义方式不好 */
    char buffer[0] = 'h';
    char buffer[1] = 'e';
    char buffer[2] = 'l';
    char buffer[3] = 'l';
    char buffer[4] = 'o';
#endif

#if 0
    /* 以字符串的方式定义 */
    char buffer[] = "Hello World Good!";

    // printf("buffer[0] = %c\n", buffer[0]);
    // printf("buffer[3] = %c\n", buffer[3]);
    // printf("buffer[7] = %c\n", buffer[7]);

    int len = sizeof(buffer) / sizeof(char);
    for (int idx = 0; idx < len; idx++)
    {
        printf("buffer[%d] = %d\n", idx, buffer[idx]);
        if (buffer[idx] >= 'a' && buffer[idx] <= 'z')
        {
            buffer[idx] = buffer[idx] - 32;
        }
    }
    for (int idx = 0; idx < len; idx++)
    {
        printf("buffer[%d] = %c\n", idx, buffer[idx]);

    }
#endif     
#endif

#if 1
    char buffer0[] = {'c', 'l', 'a', 's', 's'};//本身并没有结束符
    char buffer1[] = {'H', 'e', 'l', 'l', 'o'};
    char buffer2[] = "Hello";//末尾有结束符‘\0’

    printf("size1 = %ld\n", sizeof(buffer1));
    printf("size2 = %ld\n", sizeof(buffer2));

    printf("buffer0:%s\n", buffer0);
    printf("buffer1:%s\n", buffer1);
    printf("buffer2:%s\n", buffer2);


#endif
    return 0;
}